/*
 * Copyright (c) 2017,安徽皖通科技股份有限公司 All rights reserved.
 */

package com.wttech.dzzf.process.service.migrate;

import com.wtkj.vo.dzzf.base.kfwd.CardInfo;
import com.wtkj.vo.dzzf.base.kfwd.VehicleInfo;
import com.wttech.dzzf.process.dao.ImportHisDataDao;
import com.wttech.dzzf.process.dao.TransferUserInfoDao;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 卡片信息处理
 *
 * @author MaShibo
 * @date 2017/12/10.
 */
@Service("cardHisDataProcess")
public class CardInfoProcessService {

	@Resource
	private ImportHisDataDao importHisDataDao;

	@Resource
	private TransferUserInfoDao transferUserInfoDao;


	void process(CardInfo cardInfo) {
		String vehPlate = cardInfo.getVehiclePlate();
		Integer vehColor = cardInfo.getVehicleColor();

		if (StringUtils.isBlank(vehPlate) || vehColor == null) {
			return;
		}

		if (!vehExistsInDzzf(vehPlate, vehColor)) {
			VehicleInfo vehicleInfo = importHisDataDao.queryVehicleInfoByVheInfo(vehPlate, vehColor);
			if (vehicleInfo != null) {
				transferUserInfoDao.createDzzfObjcet(vehicleInfo);
			}
		}

	}

	private boolean vehExistsInDzzf(String vehPlate, Integer vehColor) {
		return importHisDataDao.queryDzzfVehicleInfoNum(vehPlate, vehColor) > 0;
	}
}
